package com.hcy.performancepro.controller.performanceTool;

import com.fuled.test.tool_config.DisableUtil;
import com.hcy.performancepro.bo.performanceTool.RecordControllerBo;
import com.hcy.performancepro.bo.performanceTool.RecordDaoBo;
import com.hcy.performancepro.po.performanceTool.RecordDao;
import com.hcy.performancepro.service.performanceTool.PerformanceToolDaoService;
import com.hcy.performancepro.util.ResultData;
import com.hcy.performancepro.vo.performanceTool.RecordDaoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/performanceDao")
@DisableUtil
@RequiredArgsConstructor
public class PerformanceToolDaoController {
    private final PerformanceToolDaoService performanceToolDaoService;

    @PostMapping("/page")
    public ResultData<Object> page(@RequestParam Integer currentPage, @RequestParam Integer pageSize, @RequestBody RecordDaoBo recordDaoBo){
        List<RecordDao> list = performanceToolDaoService.sarchlist(currentPage, pageSize,recordDaoBo);
        List<RecordDaoVo> listVo = new ArrayList<>();
        if(list != null && !list.isEmpty()) {
            for (RecordDao obj : list) {
                RecordDaoVo vo = new RecordDaoVo();
                BeanUtils.copyProperties(obj, vo);
                listVo.add(vo);
            }
        }
        return ResultData.ok(listVo);
    }

    @GetMapping("/count")
    public ResultData<Object> count(RecordDaoBo recordDaoBo){
        return ResultData.ok(performanceToolDaoService.countNumber(recordDaoBo));
    }
}